package com.gzu.emr.controller;

import com.gzu.emr.service.DoctorService;
import com.gzu.emr.util.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.security.auth.login.FailedLoginException;
import java.util.Map;

import static com.gzu.emr.util.ResultGenerator.genFailResult;
import static com.gzu.emr.util.ResultGenerator.genSuccessResult;

@Controller
@RequestMapping("/doctor")
public class DoctorController {

    @Resource
    private DoctorService doctorService;

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    @ResponseBody
    @Operation(summary = "医生登录")
    @Parameters({@Parameter(name = "id", description = "医生工号", required = true),
            @Parameter(name = "password", description = "密码", required = true)})
    public Result Login(@RequestBody Map<String, String> params) {
        var id = params.get("id");
        if(id == null || id.length() == 0) {
            return genFailResult("bad request body");
        }
        var password = params.get("password");
        if(password == null || password.length() == 0) {
            return genFailResult("bad request body");
        }

        if(doctorService.checkDoctorAuthority(Integer.valueOf(id), password)) {
            return genSuccessResult();
        } else {
            return genFailResult("password incorrect");
        }
    }



}
